<?php

namespace App\Backend\Controllers;

use App\Backend\Controllers\BaseController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

use App\Backend\Service\CommentService;

/**
 * 全部评论
 */
class CommentController extends BaseController
{
    private $getRules=[
            'img_url'=> 'required',
            'type'=> 'required',
            'sort'=> 'required',
            'status'=> 'required',
    ];
    private $getRulesMessage=[
            'img_url.required'=> '图片地址不能为空',
            'type.required'=> 'banner类型不能为空',
            'sort.required'=> '排序不能为空',
            'status.required'=> '状态不能为空',
    ];
    
    public function __construct(CommentService $centerService)
    {
        $this->repository = $centerService;
        parent::__construct();
    }


    /**
     * 列表
     */
    public function getList(Request $request)
    {
        //dd($request);
        $data=[
            'page'=>$request->json("page"),
            'limit'=>$request->json("limit"),
            'keyword'=>$request->json("keyword"),
            'type'=>$request->json("type"),
        ];
        $this->success($this->repository->getList($request,$data));
    }

    

    /**
     * 添加
     */
    public function add(Request $request)
    {
        $data = [
            'original_name'=>$request->json('original_name'),
            'standard_name'=>$request->json('standard_name'),


        ];
        
        $this->success($this->repository->add($request,$data));
        
    }   


     /**
     * 编辑
     */
    public function edit(Request $request)
    {
        $data=[
            'id'=>$request->json("id"),
            'original_name'=>$request->json("original_name"),
            'standard_name'=>$request->json("check_content"),
        ];
        $id =$request->json("id");
        if(empty($id)){
            $this->error('参数[id]错误');
        }
     
        $this->repository->edit($request,$data,$id);
    }

    // 详情
     public function detail(Request $request)
    {
        $unique_id = $request->json('unique_id');
        if(empty($unique_id)){
            $this->error('参数错误');
        }
        $this->success($this->repository->detail($request,$unique_id));
    }

    /**
     * 删除
     */
    public function del(Request $request)
    {
        $ids = $request->json('id');
        if(empty($ids)){
            $this->error('参数错误');
        }
        $this->repository->del($ids);
    }



}
